<template>
  <div class="wrapper">
     <swiper :options="swiperOption" v-if="showSwiper">
      <swiper-slide v-for="item in list" :key="item.id">
        <img class="swiper-img" :src="item.imgUrl"/>
      </swiper-slide>
      <div class="swiper-pagination" slot="pagination"></div>
    </swiper>
  </div>
</template>

<script>
import 'swiper/dist/css/swiper.css'
import { swiper, swiperSlide } from 'vue-awesome-swiper'
export default {
  name: 'Homeswiper',
  props: {
    list: {
      type: Array,
      default: () => []
    }
  },
  data ()  {
    return {
      swiperOption: {
        pagination: {
          el: '.swiper-pagination'
        },
        autoplay: {
          delay: 2000,
          disableOnInteraction: false // 用户操作后, autoplay会默认停止, 这个是取消禁止autoplay
        },
        loop: true // 无缝轮播
      }
    }
  },
  computed: {
    showSwiper () {
      return this.list.length
    }
  },
  components: {
    swiper,
    swiperSlide
  }
}
</script>

<style lang='scss' scoped>
// /deep/ 是sass和less的样式穿透
.wrapper /deep/ .swiper-pagination-bullet-active {
  background:#fff;
}
.wrapper {
  width: 100%;
  height: 0;
  background: #eee;
  padding-bottom: 31.25%; // 宽高比自适应 ，高度相对于宽度撑开26.66%
  overflow: hidden;
    .swiper-img {
      width: 100%;
    }
}




</style>
